#include <iostream>
using namespace std;
int a[110][310];
int n, m, vis[310], pre[310];
bool dfs(int x)
{
	int t;
	for (t = 1; t <= m; t++)
		if (a[x][t] && !vis[t])
		{
			vis[t] = 1;
			if (pre[t] == 0 || dfs(pre[t]))
			{
				pre[t] = x;
				return true;
			}
		}
	return false;
} 
int main()
{
	int T, i, t, j, s;
	scanf("%d", &T);
	while (T--)
	{
		scanf("%d%d", &n, &m);
		memset(a, 0, sizeof(a));
		memset(pre, 0, sizeof(pre));
		for (i = 1; i <= n; i++)
		{
			scanf("%d", &j);
			while (j--)
			{
				scanf("%d", &t);
				a[i][t] = 1;
			}
		}
		for (i = 1, s = 0; i <= n; i++)
		{
			memset(vis, 0, sizeof(vis));
			if (dfs(i))
				s++;
		}
		if (s == n)
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}
